home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
forth
/
amiga
/
amigaker.arc
/
11.number
< prev
next >
Wrap
Text File
|
1987-12-30
|
13KB
|
340 lines
;
; 11.number
;
; Number input, output, and conversion.
* digit (s char base -- n true | char false ) Converts char if
; in correct base, to number n.
dc.w -1
dc.l link0
link0 set *-4
dc.b $85,'digi',$80!'t'
cnop 0,2
_digit dc.l *+4
movem.l (sp),d0-d1
subi.b #'0',d1
bpl.s 1$
bra no
1$ cmpi.b #10,d1
bcs.s 2$
subq.b #7,d1
cmpi.b #10,d1
bcs no
2$ cmp.b d1,d0
bls no
move.l d1,4(sp)
bra yes
* double? (s -- fl ) Returns true if period encountered in input.
dc.w -1
dc.l link0
link0 set *-4
dc.b $87,'double',$80!'?'
cnop 0,2
_double_question dc.l nest
dc.l _dpl,_fetch,_1_plus,_0_notequal,_exit
* convert (s ud1 addr1 -- ud2 addr2 ) Starting with unsigned d1
; convert string at addr1 to d2 and leave unconvertable string addr2.
dc.w -1
dc.l link3
link3 set *-4
dc.b $87,'conver',$80!'t'
cnop 0,2
_convert dc.l nest
1$ dc.l _1_plus,_dup,_to_r
dc.l _c_fetch,_base,_fetch,_digit
dc.l _question_branch,2$
dc.l _swap,_base,_fetch,_um_times,_drop
dc.l _rot,_base,_fetch,_um_times,_d_plus
dc.l _double_question,_question_branch,3$
dc.l _1,_dpl,_plus_store
3$ dc.l _r_from,_branch,1$
2$ dc.l _drop,_r_from,_exit
* (number?) (s addr -- d flag ) Convert string at addr to a number.
; NOTE: the end of the string is found by checking for the terminating
; null.
dc.w -1
dc.l link0
link0 set *-4
dc.b $89,$28,'number?',$80!$29
cnop 0,2
_nest_number_question
dc.l nest
dc.l _0,_0,_rot,_dup,_1_plus,_c_fetch
dc.l _nest_lit,'-',_equals,_dup,_to_r,_minus
dc.l _dpl,_on
1$ dc.l _convert,_dup,_c_fetch,_nest_lit,','
dc.l _nest_lit,'/',_between
dc.l _question_branch,2$
dc.l _dpl,_off
dc.l _branch,1$
2$ dc.l _minus_rot
dc.l _r_from,_question_branch,3$
dc.l _dnegate
3$ dc.l _rot,_c_fetch,_0_equal,_exit
* number? (s addr -- d flag ) Convert string into a number, observes
; a minus sign, sets dpl to position of a delimiter, String must end in a
; null.
dc.w -1
dc.l link2
link2 set *-4
dc.b $87,'number',$80!'?'
cnop 0,2
_number_question dc.l nest
dc.l _false,_over,_count,_bounds
dc.l _nest_question_do,2$
1$ dc.l _i,_c_fetch,_base,_fetch,_digit,_nip
dc.l _question_branch,3$
dc.l _drop,_true,_nest_leave
3$ dc.l _nest_loop,1$
2$ dc.l _question_branch,4$
dc.l _nest_number_question,_branch,5$
4$ dc.l _drop,_0,_0,_false
5$ dc.l _exit
* (number) (s addr -- d ) Converts the string to a double number. The
; string must be null terminated, regards a minus sign and stores the
; decimal point location in dpl.
; Normally this word is the end of the search for a match in the current
; vocabulary. Then if it is not a number the word '?missing' is run,
; printing a message on the screen.
dc.w -1
dc.l link0
link0 set *-4
dc.b $88,$28,'number',$80!$29
cnop 0,2
_nest_number dc.l nest
dc.l _number_question,_not,_question_missing
dc.l _exit
* number Deferred word, usually set to (number)
dc.w -1
dc.l link2
link2 set *-4
dc.b $86,'numbe',$80!'r'
cnop 0,2
_number dc.l dodefer,_nest_number
* hold (s char -- ) Stores a character in a temporary storage
; space pointed to by hld. Stores characters in stack like format.
dc.w -1
dc.l link0
link0 set *-4
dc.b $84,'hol',$80!'d'
cnop 0,2
_hold dc.l nest
dc.l _minus_1,_hld,_plus_store
dc.l _hld,_fetch,_c_store,_exit
* <# (s -- ) Sets hld to a storage space, currently pad, which
; is 160 bytes above here. Prepares for number to string conversion.
dc.w -1
dc.l link0
link0 set *-4
dc.b $82,$3C,$80!$23
cnop 0,2
_less_sharp dc.l nest
dc.l _pad,_hld,_store
dc.l _exit
* #> (s d# -- addr len ) Ends number conversion, returns the
; address and the length of the string.
dc.w -1
dc.l link3
link3 set *-4
dc.b $82,$23,$80!$3e
cnop 0,2
_sharp_greater dc.l nest
dc.l _2drop,_hld,_fetch,_pad,_over,_minus
dc.l _exit
* sign (s n -- ) Stores a minus sign at hld.
dc.w -1
dc.l link3
link3 set *-4
dc.b $84,'sig',$80!'n'
cnop 0,2
_sign dc.l nest
dc.l _0_less,_question_branch,1$
dc.l _nest_lit,'-',_hold
1$ dc.l _exit
* # (s d# -- d# ) converts a single digit in the current base
dc.w -1
dc.l link3
link3 set *-4
dc.b $81,$80!$23
cnop 0,2
_sharp dc.l nest
dc.l _base,_fetch,_um_divide_mod,_rot
dc.l _nest_lit,9,_over,_less_than
dc.l _question_branch,1$,_nest_lit,7,_plus
1$ dc.l _nest_lit,'0',_plus,_hold,_exit
* #S (s d# -- d# ) Converts an entire number.
dc.w -1
dc.l link3
link3 set *-4
dc.b $82,$23,$80!'S'
cnop 0,2
_sharp_s dc.l nest
1$ dc.l _sharp,_2dup,_or,_0_equal
dc.l _question_branch,1$
dc.l _exit
* hex Sets number base to 16
dc.w -1
dc.l link0
link0 set *-4
dc.b $83,'he',$80!'x'
cnop 0,2
_hex dc.l nest
dc.l _nest_lit,16,_base,_store,_exit
* decimal Sets number base to 10, the default.
dc.w -1
dc.l link0
link0 set *-4
dc.b $87,'decima',$80!'l'
cnop 0,2
_decimal dc.l nest
dc.l _nest_lit,10,_base,_store,_exit
* octal Sets number base to 8
dc.w -1
dc.l link3
link3 set *-4
dc.b $85,'octa',$80!'l'
cnop 0,2
_octal dc.l nest
dc.l _nest_lit,8,_base,_store,_exit
* binary Sets number base to 2.
dc.w -1
dc.l link2
link2 set *-4
dc.b $86,'binar',$80!'y'
cnop 0,2
_binary dc.l nest
dc.l _2,_base,_store,_exit
* (u.) (s u -- a l ) Converts unsigned number to a string
dc.w -1
dc.l link0
link0 set *-4
dc.b $84,$28,'u',$2E,$80!$29
cnop 0,2
_nest_u_dot dc.l nest
dc.l _0,_less_sharp,_sharp_s,_sharp_greater,_exit
* u. (s u -- ) Prints output number and a trailing space.
dc.w -1
dc.l link1
link1 set *-4
dc.b $82,'u',$80!$2E
cnop 0,2
_u_dot dc.l nest
dc.l _nest_u_dot,_type,_space,_exit
* u.r (s u l -- ) Prints unsigned number in a field of l spaces
; right justified.
dc.w -1
dc.l link1
link1 set *-4
dc.b $83,'u.',$80!'r'
cnop 0,2
_u_dot_r dc.l nest
dc.l _to_r,_nest_u_dot,_r_from,_over
dc.l _minus,_spaces,_type,_exit
* (.) (s n -- a l ) Convert signed number to a string.
dc.w -1
dc.l link0
link0 set *-4
dc.b $83,'(.',$80!')'
cnop 0,2
_nest_dot dc.l nest
dc.l _dup,_abs,_0,_less_sharp,_sharp_s
dc.l _rot,_sign,_sharp_greater,_exit
* . (s n -- ) Prints signed number and a trailing space.
dc.w -1
dc.l link2
link2 set *-4
dc.b $81,$80!$2e
cnop 0,2
_dot dc.l nest
dc.l _nest_dot,_type,_space,_exit
* .r (s n l -- ) Print right justified signed number.
dc.w -1
dc.l link2
link2 set *-4
dc.b $82,$2E,$80!'r'
cnop 0,2
_dot_r dc.l nest
dc.l _to_r,_nest_dot,_r_from,_over,_minus
dc.l _spaces,_type,_exit
* (ud.) (s ud -- a l ) Converts unsigned double into a string.
dc.w -1
dc.l link0
link0 set *-4
dc.b $85,'(ud.',$80!')'
cnop 0,2
_nest_ud_dot dc.l nest
dc.l _less_sharp,_sharp_s,_sharp_greater,_exit
* ud. (s ud -- ) prints unsigned double and trailing space
dc.w -1
dc.l link1
link1 set *-4
dc.b $83,'ud',$80!'.'
cnop 0,2
_ud_dot dc.l nest
dc.l _nest_ud_dot,_type,_space,_exit
* ud.r (s ud l -- ) prints unsigned double right justified
dc.w -1
dc.l link1
link1 set *-4
dc.b $84,'ud.',$80!'r'
cnop 0,2
_ud_dot_r dc.l nest
dc.l _to_r,_nest_ud_dot,_r_from,_over
dc.l _minus,_spaces,_type,_exit
* (d.) (s d -- a l ) Convert signed double to a string.
dc.w -1
dc.l link0
link0 set *-4
dc.b $84,'(d.',$80!'r'
cnop 0,2
_nest_d_dot dc.l nest
dc.l _tuck,_dabs,_less_sharp,_sharp_s
dc.l _rot,_sign,_sharp_greater,_exit
* d. (s d -- ) Print signed double followed by a space.
dc.w -1
dc.l link0
link0 set *-4
dc.b $82,'d',$80!'.'
cnop 0,2
_d_dot dc.l nest
dc.l _nest_d_dot,_type,_space,_exit
* d.r (s d -- ) print signed double right justified.
dc.w -1
dc.l link0
link0 set *-4
dc.b $83,'d.',$80!'r'
cnop 0,2
_d_dot_r dc.l nest
dc.l _to_r,_nest_d_dot,_r_from,_over
dc.l _minus,_spaces,_type,_exit